package org.kailu.book.DAO;

import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.kailu.book.entity.ExportBookDetailsEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class ExportBookDetailsDAO {

	@Autowired
	private SessionFactory sessionFactory;
	
	public void save(ExportBookDetailsEntity bookDetailsEntity) {
		this.sessionFactory.getCurrentSession().saveOrUpdate(bookDetailsEntity);
	}
	
	@SuppressWarnings("unchecked")
	public List<ExportBookDetailsEntity> getAll() {
		return this.sessionFactory.getCurrentSession().createCriteria(ExportBookDetailsEntity.class).list();
	}
	
	public ExportBookDetailsEntity get(int id) {
		return (ExportBookDetailsEntity) this.sessionFactory.getCurrentSession().get(ExportBookDetailsEntity.class, id);
	}
	
	@SuppressWarnings("unchecked")
	public List<ExportBookDetailsEntity> getByExportId(int export_id) {
		return this.sessionFactory.getCurrentSession().createCriteria(ExportBookDetailsEntity.class).add(Restrictions.eq("export.exportId", export_id)).list();
	}
	
	public void delete(int id) {
		ExportBookDetailsEntity exportBookDetailsEntity = (ExportBookDetailsEntity) this.sessionFactory.getCurrentSession().get(ExportBookDetailsEntity.class, id);
		
		if (exportBookDetailsEntity != null) {
			this.sessionFactory.getCurrentSession().delete(exportBookDetailsEntity);
		}
	}
}
